package com.work.game.home.ui.activity;


import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.Request;
import com.work.game.R;
import com.work.game.config.UrlConfig;
import com.work.game.home.ui.model.vo.FeedbackVo;
import com.work.game.home.ui.model.User;
import com.work.game.volley.BaseActivity;
import com.work.game.volley.state.HUCState;

public class ProblemFeedbackActivity extends BaseActivity {

    private EditText etContent;
    private TextView tvNumber;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_problem_feedback);
        super.onCreate(savedInstanceState);
        tvActionbarTitle.setText("问题反馈");
    }

    @Override
    public void initView() {
        super.initView();
        etContent = findViewById(R.id.et_content);
        tvNumber = findViewById(R.id.tv_number);
    }

    @Override
    public void initClick() {
        super.initClick();
        etContent.addTextChangedListener(this);
        findViewById(R.id.tv_user_feedback).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_user_feedback:
                String content = etContent.getText().toString();
                if (content.length() < 6) {
                    showToast("最少输入5个字以上");
                    return;
                }
                showToast("提交成功");
                userFeedback();
                break;
            default:
                break;
        }
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        super.onTextChanged(s, start, before, count);
        tvNumber.setText(etContent.getText().length() + "/200");

    }

    private void userFeedback() {
        FeedbackVo baseVo = new FeedbackVo();
        baseVo.setToken(getSharedPreferences("deviceId"));
        baseVo.setContent(etContent.getText().toString());
        hucRequestInterfase.executeStr(this, User.class,
                HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.URL_USER_FEEDBACK,
                hucParameInterfase.getRequestParameter(baseVo), true);
        loading();
    }

    @Override
    public void onSuccessfulStrType(int inputType, Object response) {
        super.onSuccessfulStrType(inputType, response);
        showToast("提交成功");
        loadDismiss();
    }

    @Override
    public void onFailStrType(int inputType, Object response) {
        super.onFailStrType(inputType, response);
        showToast(response.toString());
        loadDismiss();
    }
}